<template>
  <div id="headBox" class="pageNormalBackground">
    <headerT title="立即提现" />
    <div class="headMarginTop boxMain" style="height:100vh">
      <div class="everyBlockBgcolor exchangeBox">
        <div class="exchangePadding">
          <div class="dqjifen">现有现金 {{userBalance}}</div>
          <div class="displayFlex jifen money">
            <p>￥</p>
            <input type="number" v-model="inputMoney" @input="inputNum" />
          </div>
          <div class="displayFlex keExchange" v-if="inputMoney>=1">
            <p>可提现金￥{{inputMoney}}</p>
            <p @click="btnAllMoeny">全部提现</p>
          </div>
          <div class="displayFlex keExchange " v-if="inputMoney<1 && userBalance>=1">
            <p>当前输入的金额小于1元，不能提现</p>
            <p></p>
          </div>
          <div class="displayFlex keExchange" v-if="inputMoney<1 && userBalance<1">
            <p>当前金额不足，不能兑换现金</p>
            <p></p>
          </div>
        </div>
      </div>
      <div class="exchangeBg" @click="btnTixian">确认提现</div>
    </div>
  </div>
</template>

<script>
import headerT from "@/components/header";
import { userInfo, userDeposit } from "@/services/personCenter";
export default {
  components: {
    headerT
  },
  name: "",

  data() {
    return {
      userBalance: 0, //用户当前现金
      inputMoney: 1, //输入提现金额（提现最少金额为1元）
      tixianMoeny: 1 //可以提取的金额
    };
  },
  created() {
    this.getUserInfo();
  },
  watch: {},

  methods: {
      btnAllMoeny(){//全部提现
        this.inputMoney=Number(this.userBalance.toFixed(0))
      },
    inputNum() {
      this.inputMoney = Number(this.inputMoney).toFixed(0);
      if (this.inputMoney < 1) {
        this.inputMoney = "";
      }
    },
    btnTixian() {
      //确认提现
      const _this = this;
      if (this.inputMoney > this.userBalance ) {
        
        this.$vux.toast.text("输入的积分不能大于当前积分！！！", 'top')
        return;
      }
      this.$vux.loading.show({
        text: "Loading"
      });
      _this.$post(userDeposit, { balance: _this.inputMoney }).then(res => {
        _this.$vux.loading.hide();
        if(res.code==200){
           
            this.$vux.toast.text(res.message, 'middle')
            _this.getUserInfo()
        }
      }).catch(error => {
          _this.$vux.loading.hide();
        });
    },
    getUserInfo() {
      //获取用户信息
      this.$post(userInfo).then(res => {
        if (res.code == 200 && res.data != null) {
          this.userBalance = res.data.balance;

          this.inputMoney = Number(this.userBalance.toFixed(0));
        }
      });
    }
  }
};
</script>

<style lang="less" rel="stylesheet/less" type="text/css" scoped>
@colorRed: #f64135;
@fontsize32: 0.32rem;
#headBox {
  .boxMain {
    padding: 0.2rem 0;
    .exchangeBox {
      //   height: 4.24rem;
      margin: 0.49rem 0.34rem 0.52rem 0.37rem;
      .exchangePadding {
        padding: 0 0.34rem 0.34rem 0.49rem;
        color: #4e4e4e;
        font-size: 0.3rem;
        .dqjifen {
          padding: 0.5rem 0 0 0;
        }
        .jifen {
          font-size: 1.23rem;
          font-weight: bold;
        }
        .money {
          input {
            height: 100%;
            width: 95%;
            border: none;
            padding: 0.3rem;
            font-size: 1.23rem;
            font-weight: bold;
          }
        }
        .keExchange {
          margin-top: 0.4rem;
          justify-content: space-between;
          p:last-child {
            color: #f78c37;
            padding: 0.2rem 0.3rem;
          }
        }
      }
    }
    .exchangeBg {
      height: 2.02rem;
      background-image: url("/static/images/changeBg.png");
      background-size: 100%;
      font-size: 0.39rem;
      text-align: center;
      line-height: 2.02rem;
      color: #ffffff;
    }
  }
}
</style>
